package com.bupt.cosmfl.cosmflweb.controller;

import ch.ethz.ssh2.Connection;
import com.bupt.cosmfl.cosmflweb.util.RemoteCommandUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/admin")
public class LoginController {

    @GetMapping
    public String loginPage() {
        return "admin/login";
    }

    @PostMapping("/login")
    public String login(@RequestParam String ip, @RequestParam String userName, @RequestParam String userPwd) {
        Connection conn = RemoteCommandUtil.login(ip, userName, userPwd);
        if (RemoteCommandUtil.flag == false){
            return "fail";
        }
        RemoteCommandUtil.execute(conn, "cd /home/pi/PySyft/&&python3 run_websocket_server.py --host 10.128.242.44 --port 8777 --id alice");
        return "success";
    }

}
